﻿using MDK.Common;
using MDK.Device;
using MDK.Model.Models;
using System;
using MDK.Winform.UserControl.Config;
using Newtonsoft.Json;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using MDK.WebApi;
using System.Drawing;
using System.Speech.Synthesis;
using MDK.Common.Helper;

namespace MDK.Winform
{
    public class App
    {
        public static User currentUser { get; set; }

        public static SystemSettings systemSetting { get; set; }

        public static Flow flow { get; set; }

        public static Back2Flow back2flow { get; set; }

        public static Bitmap BitMap { get; set; }

        public static SpeechSynthesizer speech
        {
            get { return SpeechHelper.Speech; }
        }

        /// <summary>
        /// 初始化配置
        /// </summary>
        public static void LoadSystemSettings()
        {
            systemSetting = new SystemSettings();
          
        }
        
        /// <summary>
        /// 初始化用户
        /// </summary>
        /// <param name="user"></param>
        public static void LoadUser(T_User user)
        {
            currentUser = new User(user);
        }

        /// <summary>
        /// 开启前处理流程
        /// </summary>
        public static void StartFlow()
        {
            flow = new Flow();
            flow.Initialize();
            flow.Start(true);
        }
    }

    public class SystemSettings : Dictionary<string, string>
    {
        public SystemSettings()
        {
            string jsonWhere = "";
            PropertyHelper property = new PropertyHelper();
            property.Addproperty(CompareType.Contains, "Is_Enable", true);
            jsonWhere = JsonConvert.SerializeObject(property.propertyList);
            string url = string.Format("Systemsetting/FindList?jsonWhere={0}&orderPropertyName={1}&isAsc=false", "", "");
            var list = WebAPIHelper.Get<List<T_Systemsetting>>(url);

            foreach (var info in list)
            {
                this.Add(info.SysKey, info.SysValue);
            }
        }
    }

    public class User
    {
        public User(T_User user)
        {
            LoginID = user.Id;
            FingerID = user.FingerID;
            LoginName = user.LoginName;
            RealName = user.RealName;
            IsAdmin = user.Is_Admin;
        }

        public string LoginID { get; set; }

        public int? FingerID { get; set; }

        public string LoginName { get; set; }

        public string RealName { get; set; }

        public bool IsAdmin { get; set; }

    }
}


